<?php

class ActivityController extends Controller {

//    public $layout = '//layouts/aboutmain';
    public $s;

    public function filters() {
        return array(
            'accessControl', // perform access control for CRUD operations
        );
    }

    public function accessRules() {
        return array(
            array('allow', // allow authenticated users to access all actions
                'users' => array('*'),
            ),
        );
    }

    public function init() {
        $this->s = $_GET['s'] ? $_GET['s'] : 'ten';
        $cs = Yii::app()->clientScript;
        $cs->registerCssFile(Yii::app()->baseUrl . '/css/common.css');
		$cs->registerCssFile(Yii::app()->baseUrl . '/css/v3/n_common.css');
//        $cs->registerCssFile(Yii::app()->baseUrl . '/css/activity.css');
        $cs->registerScriptFile(Yii::app()->request->baseUrl . "/js/common.js", CClientScript::POS_HEAD);
		$cs->registerScriptFile(Yii::app()->request->baseUrl . "/js/v3/n_common.js", CClientScript::POS_HEAD);
        $cs->registerCoreScript('jquery');
    }

    public function actions() {
        return array(
            'captcha' => array(
                'class' => 'CCaptchaAction',
                'backColor' => 0xFFFFFF,
            ),
            'page' => array(
                'class' => 'CViewAction',
            ),
        );
    }

    public function actionIndex() {
        $api = new Api('account');
        $commonclass = new CommonClass();
        /*
         * 获取cookie商圈ID
         */
        $cookie = Yii::app()->request->getCookies();
        $zonecookie = (string) $cookie['zone'];
        $zonecookie = !$zonecookie ? '2' : $zonecookie;
        $zoneid = !$zonecookie ? '&fq=zoneId:2' : '&fq=zoneId:' . $zonecookie;
        $zone_row = $commonclass->zoneProduct($zonecookie);

        $this->pageTitle = '活动';
        if ($this->s == 'ten') {
            $model = new ProductForm();

            $apiurl = "/LdAccountServer/userAccount/getUerIdByPidCount";
            $params = array(
                'GetUerIdByPidCountReq' => array(
                    'userId' => Yii::app()->user->id
                )
            );
            $count = $api->apiclient($apiurl, $params);

            $apiurl_chk = "/LdAccountServer/userAccount/getBuyerCoupons";
            $params_chk = array(
                'GetBuyerCouponsReq' => array(
                    'buyerId' => Yii::app()->user->id,
                    'modelId' => 2
                )
            );
            $row_chk = $api->apiclient($apiurl_chk, $params_chk);
            if (count($row_chk['GetBuyerCouponsListRsp']['list']) > 0) {
                $flag = false;
            } else {
                $flag = true;
            }

            $this->render($this->s, array('row' => $row, 'count' => $count['GetUerIdByPidCountRsp']['count'], 'model' => $model,'flag'=>$flag));
        } elseif ($this->s == 'pm') {
            $apiurl = "/LdAccountServer/userAccount/queryRank";
            $params = array(
                'GetUserPidRankReq' => array(
                    'page' => 10
                )
            );
            $row = $api->apiclient($apiurl, $params);

            $this->render($this->s, array('row' => $row));
        }
    }

}

?>